package com.data.app.dao.primary;

import com.data.app.pojo.primary.YhDisastersEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface YhDisasterBaseDao  extends JpaRepository<YhDisastersEntity, String> {

//    @Query(nativeQuery = false,value = "SELECT create_time FROM yh_disaster WHERE yh_project_task =:type ORDER BY create_time DESC LIMIT 1")
//    LocalDateTime getCreateTime(String type);

    /**
     * 数据从住建pg库迁移到二测mysql库 --验重
     * @param code
     * @param isValid
     * @param yhProjectType
     * @return
     */
    List<YhDisastersEntity> findByYhCodeAndIsValidAndYhProjectType(String code, String isValid, String yhProjectType);

    //验重
    // @Query(value = "SELECT yh_code,yh_project_type FROM yh_disaster WHERE is_valid='1' ",nativeQuery = true)
    // List<Object[]> findYhCodeAndYhProjectTypeByIsValid();

    @Query(value = "SELECT id,yh_code,yh_project_type FROM yh_disaster WHERE is_valid='1' ",nativeQuery = true)
    List<Object[]> findByIsValid();

    @Query(value = "select dic_value from sys_dictionary where dic_type='PROJECT_TYPE' AND dic_status='enable' AND dic_key=(select dic_key from sys_dictionary where dic_type='CONSTR_APPL' AND dic_status='enable' and dic_value = :value)", nativeQuery = true)
    String findValueByConstrAppl(String value);


    @Query(value = "select id from sys_dictionary where dic_type='PROJECT_TYPE' AND dic_status='enable' AND dic_value= :projectType", nativeQuery = true)
    String findByProjectType(String projectType);
}
